//
//  KSMultiSelectCell.swift
//  Slaughter
//
//  Created by 邱仙凯 on 2019/9/19.
//  Copyright © 2019 zwb. All rights reserved.
//

import UIKit

class KSMultiSelectCell: UITableViewCell {
    
    var inputNumberClosure:((String)->())?
    
    var left1 :UILabel = UILabel()
    var left2 :UILabel = UILabel()
    var left3 :UILabel = UILabel()
    var left4 :UILabel = UILabel()
    lazy var inputDesc:UILabel = {
        let v :UILabel = UILabel()
        v.font = UIFont.systemFont(ofSize:15)
        v.textColor = .lightGray
        return v
    }()
    lazy var input:UITextField = {
       let v: UITextField = UITextField()
        v.isUserInteractionEnabled = false
        return v
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.contentView.addSubview(left1)
        left1.font = UIFont.systemFont(ofSize: 15)
        left1.numberOfLines = 2
        left1.snp.makeConstraints { (make) in
            make.left.equalTo(self.contentView).offset(15)
            make.width.equalTo(KSGlobal.screenW - 130)
            make.top.equalTo(self).offset(8)
        }
        
        self.contentView.addSubview(left2)
        left2.font = UIFont.systemFont(ofSize: 15)
        left2.snp.makeConstraints { (make) in
            make.left.equalTo(left1)
            make.top.equalTo(left1.snp.bottom).offset(8)
        }
        self.contentView.addSubview(left3)
        left3.font = UIFont.systemFont(ofSize: 15)
        left3.numberOfLines = 0
        left3.snp.makeConstraints { (make) in
            make.left.equalTo(left1)
            make.right.equalTo(self.contentView).offset(-20)
            make.top.equalTo(left2.snp.bottom).offset(8)
        }
        self.contentView.addSubview(left4)
        left4.font = UIFont.systemFont(ofSize: 15)
        left3.numberOfLines = 0
        left4.snp.makeConstraints { (make) in
            make.left.equalTo(left1)
            make.right.equalTo(self.contentView).offset(-20)
            make.top.equalTo(left3.snp.bottom).offset(8)
        }
        
        
    }
    func addInput(desc:String) {
        addSubview(input)
        input.borderStyle = .roundedRect
        input.addTarget(self, action: #selector(KSMultiSelectCell.textFieldDidChange(_:)), for: .editingChanged)
        
        input.keyboardType = .decimalPad
        input.snp.makeConstraints { (make) in
            make.right.equalTo(self).offset(-35)
            make.height.equalTo(35)
            make.bottom.equalTo(self).offset(-8)
            make.width.equalTo(120)
        }
        addSubview(inputDesc)
        inputDesc.text = desc
        inputDesc.snp.makeConstraints { (make) in
            make.left.equalTo(left1)
            make.centerY.equalTo(input)
        }
    }
    
    
    @objc func textFieldDidChange(_ textField: UITextField) {
        if let textValue = textField.text {
            if let clo = inputNumberClosure {
                clo(textValue)
            }
        } else {
            if let clo = inputNumberClosure {
                clo("")
            }
        }
        
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}


